#ifndef URLTASKS_H
#define URLTASKS_H

#include <QAbstractTableModel>
#include <QNetworkAccessManager>
#include <QVariant>
#include <QList>

#include "urltask.h"
#include "settingsmanager.h"

class UrlTasks : public QAbstractTableModel
{
    Q_OBJECT

private:
    QList<UrlTask> m_tasks;
    QNetworkAccessManager m_manager;
    SettingsManager m_settings;

private slots:
    void item_changed(UrlTask const &task);

public slots:
    void sort(int column, Qt::SortOrder order);

public:
    explicit UrlTasks(QObject *parent = 0);
    virtual ~UrlTasks();

    virtual int rowCount(const QModelIndex &parent) const;
    virtual int columnCount(const QModelIndex &parent) const;
    virtual QVariant data(const QModelIndex &index, int role) const;
    virtual QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
    virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const;

    void create_new_task(QString const &url, QString const &file, UrlTask::TaskStatus status = UrlTask::STOPPED);
    void delete_task_at(QModelIndex const &index);
};

#endif // URLTASKS_H
